<?php

class Manager_CategoryController extends Zend_Controller_Action
{
    protected $form = null;
    protected $dbCat = null;
    public function init()
    {
        $this->form = new Manager_Form_Category();
        $this->dbCat = new Manager_Model_Category();
    }

    public function indexAction()
    {
      $this->view->form= $this->dbCat->getData();
    }
    public function formAction(){
     $this->view->form = $this->form;
        
      $request = $this->getRequest();
       if($request->isPost()){
           $dataForm = $request->getPost();
           if($this->form->isValid($dataForm)){
                   $categoryName=$this->form->getValue('Category_Name');
                   $categoryInfo =$this->form->getValue('Category_Info'); 
                   $categoryParent=$this->form->getValue('Category_Parent'); 
                   $data = array('category_name'=>$categoryName,'category_info'=>$categoryInfo,'parent'=>$categoryParent);
                   $this->dbCat->categoryInserted($data);
                       $this->_redirect('manager/category');
           }
       }
    }
    public function deletedAction(){
       $this->_helper->layout->disableLayout();
       $request = $this->getRequest();
       
       if($request->isPost()){
           
           $id = $request->getPost('Category_code');
       
        if(!empty($id)){
            if(strpos($id,',')){ 
                $arr =explode(',',$id);
                foreach($arr as $each){$this->dbCat->deletedSelected($each);} }
             else{ $this->dbCat->deletedSelected($id); }
        }
           
       }
    }

}

